package com.ccc.netty.server;

import com.ccc.netty.server.base.MyNettyServer;
import com.ccc.netty.server.splitpacket.SplitpacketNettyServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * 配置类
 *
 * @author superC
 * @version 1.0.0
 * @date 2022/8/24
 */

@Configuration
public class NettyServerConfig {
    protected static final Logger logger = LoggerFactory.getLogger(NettyServerConfig.class);

    /**
     * 粘包拆包、拆分包
     */
    @Autowired
    private SplitpacketNettyServer splitpacketNettyServer;

    /**
     * Base
     */
    @Autowired
    private MyNettyServer nettyClient;


    @PostConstruct
    private void startMonitorServer() {
        try {
            new Thread(() -> {
                try {
                    testBase();
//                    testSplit();
                } catch (Exception e) {
                    logger.debug(e.toString());
                }
            }).start();
        } catch (Exception e) {
            logger.error("【捕获异常-启动netty server】\r\n异常记录：", e);
        }
    }

    private void testSplit() throws Exception {
        splitpacketNettyServer.start(9000);
    }

    private void testBase() throws Exception {
        nettyClient.run();
    }
}